console.log('-------------- search -----------------')
const helper = new Helper(this);
// 搜索框
const communicationName = __artemis__tree.getSearchText();
// 融合通讯列表
const organizationWidgetObj = helper.get('tree_organization')?.widgetObj;
const artemis = helper.get('三维组件')?.widgetObj.artemis;
const [ select ] = $event;

function renderOrgTree (result) {
    let dataSource = result.map(__artemis__tree.breakDataSource);

    if (select.value === 'all') {
        dataSource = artemis.resetUsersStatus(dataSource)
    } else {
        dataSource = artemis.filterUsersOnline(dataSource)
    }

    if (organizationWidgetObj) {
        organizationWidgetObj._option.dataSource = dataSource;
        organizationWidgetObj.render();
    }
}

if (__artemis__tabs.tabCheckedNum === 3) {
    __artemis__tree.loadAccountListData({ communicationName }).then(result => {
        if (Array.isArray(result)) renderOrgTree(result)
    });
} else {
    if (__artemis__tabs.tabCheckedNum === 1) {
        __artemis__tree.loadOrgListData({ communicationName }).then(result => {
            if (Array.isArray(result)) renderOrgTree(result)
        });
    } else if (__artemis__tabs.tabCheckedNum === 2) {
        __artemis__tree.loadGroupListData({ communicationName }).then(result => {
            if (Array.isArray(result)) renderOrgTree(result)
        });
    }
}
